package com.poly.police.monitor.admin.controller.sys;

import com.poly.police.monitor.application.service.sys.ISysPostService;
import com.poly.police.monitor.common.aop.NotPower;
import com.poly.police.monitor.common.core.AjaxResult;
import com.poly.police.monitor.common.core.PageResult;
import com.poly.police.monitor.common.validator.annotation.IDMust;
import com.poly.police.monitor.pojo.validate.commons.IdValidate;
import com.poly.police.monitor.pojo.validate.commons.PageValidate;
import com.poly.police.monitor.pojo.validate.sys.SysPostCreateValidate;
import com.poly.police.monitor.pojo.validate.sys.SysPostSearchValidate;
import com.poly.police.monitor.pojo.validate.sys.SysPostUpdateValidate;
import com.poly.police.monitor.pojo.vo.sys.SysPostVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/sys/post")
@Api(tags = "系统岗位管理")
public class SysPostController {

    @Resource
    ISysPostService iSysPostService;

    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="所有岗位")
    public AjaxResult<List<SysPostVo>> all() {
        List<SysPostVo> list = iSysPostService.all();
        return AjaxResult.success(list);
    }

    @GetMapping("/list")
    @ApiOperation(value="岗位列表")
    public AjaxResult<PageResult<SysPostVo>> list(@Validated PageValidate pageValidate,
                                                         @Validated SysPostSearchValidate searchValidate) {
        PageResult<SysPostVo> list = iSysPostService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="岗位详情")
    public AjaxResult<SysPostVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        SysPostVo vo = iSysPostService.detail(id);
        return AjaxResult.success(vo);
    }

    @PostMapping("/add")
    @ApiOperation(value="岗位新增")
    public AjaxResult<Object> add(@Validated @RequestBody SysPostCreateValidate createValidate) {
        iSysPostService.add(createValidate);
        return AjaxResult.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value="岗位编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody SysPostUpdateValidate updateValidate) {
        iSysPostService.edit(updateValidate);
        return AjaxResult.success();
    }

    @PostMapping("/del")
    @ApiOperation(value="岗位删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iSysPostService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
